package com.videoaggre.zcl.db

import androidx.room.*
import kotlinx.coroutines.flow.Flow

@Dao
interface AgefansDao {
    @Query("SELECT * FROM AgefansSearchKeywordHistory")
    suspend fun getSearchKeywordHistoryAll(): List<AgefansSearchKeywordHistory>

    @Insert
    suspend fun insertAll(vararg users: AgefansSearchKeywordHistory)

    /*@Query("SELECT * FROM user")
    fun getAll(): List<User>

    @Query("SELECT * FROM user WHERE uid IN (:userIds)")
    fun loadAllByIds(userIds: IntArray): List<User>

    @Query("SELECT * FROM user WHERE first_name LIKE :first AND  last_name LIKE :last LIMIT 1")
    fun findByName(first: String, last: String): User

    @Insert
    fun insertAll(vararg users: User)

    @Delete
    fun delete(user: User)*/
}

@Dao
interface QimanDao {
    @Query("SELECT * FROM QimanComicHistory ORDER BY updateTime DESC")
    fun getQimanComicHistoryAll(): Flow<MutableList<QimanComicHistory>>

    @Query("SELECT * FROM QimanComicBrowse WHERE serieId = :serieId")
    suspend fun queryQimanComicBrowseById(serieId: String): QimanComicBrowse?

    @Query("SELECT * FROM QimanComicDetail WHERE id = :id")
    suspend fun queryQimanComicDetailById(id: String): QimanComicDetail?

    @Transaction
    suspend fun addQimanComicHistory(qimanComicHistory: QimanComicHistory) {
        if (updateQimanComicHistory(qimanComicHistory) == 0) {
            insert(qimanComicHistory)
        }
    }

    @Transaction
    suspend fun addQimanComicBrowse(qimanComicBrowse: QimanComicBrowse) {
        if (updateQimanComicBrowse(qimanComicBrowse) == 0) {
            insert(qimanComicBrowse)
        }
    }

    @Transaction
    suspend fun addQimanComicDetail(qimanComicDetail: QimanComicDetail) {
        if (updateQimanComicDetail(qimanComicDetail) == 0) {
            insert(qimanComicDetail)
        }
    }

    @Update
    suspend fun updateQimanComicHistory(qimanComicHistory: QimanComicHistory): Int

    @Insert
    suspend fun insert(qimanComicHistory: QimanComicHistory)

    @Update
    suspend fun updateQimanComicBrowse(qimanComicBrowse: QimanComicBrowse): Int

    @Insert
    suspend fun insert(qimanComicBrowse: QimanComicBrowse)

    @Update
    suspend fun updateQimanComicDetail(qimanComicDetail: QimanComicDetail): Int

    @Insert
    suspend fun insert(qimanComicDetail: QimanComicDetail)
}